package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.TokenVisitorInterface;

public class TIPOFactory extends AbstractTokenVisitorFactory {

	private static TIPOFactory INSTANCE;
	
	private TIPO1Factory tipo1Factory;
	private TIPO2Factory tipo2Factory;
	
	public static TIPOFactory getInstance() throws Exception {
		if(INSTANCE==null) INSTANCE = new TIPOFactory();
		return INSTANCE;
	}
	
	private Initializer initializer = new Initializer() {
		
		@Override
		public void init() {
			initializer = NoOperationInitializer.getInstance();
			tipo1Factory = TIPO1Factory.getInstance();
			tipo2Factory = TIPO2Factory.getInstance();
		}
	};
	
	private TIPOFactory() throws Exception {
		initializer.init();
	}
	
	@Override
	public TokenVisitorInterface makeChainedVisitor(
			final TokenVisitorInterface siguiente) throws Exception {
		return tipo1Factory.makeChainedVisitor(tipo2Factory.makeChainedVisitor(siguiente));
	
	}
	@Override
	public TokenVisitorInterface makeVisitor() throws Exception {
		return tipo1Factory.makeChainedVisitor(tipo2Factory.makeVisitor());
	}
	
	
}
